package com.kkd.kkdapp.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.HorizontalScrollView;

import com.kkd.kkdapp.utils.SystemUtils;

public class HorScrollView extends HorizontalScrollView {

	private OnScrollListener onScrollListener;
	private XianduanView myView;
	private int screenWidth;// 屏幕宽度

	public HorScrollView(Context context, AttributeSet attrs) {
		super(context, attrs);
		screenWidth = SystemUtils.getScreenWidth(getContext());
	}

	@Override
	protected void onScrollChanged(int l, int t, int oldl, int oldt) {
		super.onScrollChanged(l, t, oldl, oldt);
		if (onScrollListener != null) {
			if (l < 0) {
				onScrollListener.onScroll(myView.getMid(0));
			} else if (l > (myView.getShouldWidth() - screenWidth)) {
				onScrollListener.onScroll(myView.getMid(myView.getShouldWidth()
						- screenWidth));
			} else {
				onScrollListener.onScroll(myView.getMid(l));
			}
		}
	}

	public void setOnScrollListener(OnScrollListener onScrollListener,
			XianduanView myView) {
		this.onScrollListener = onScrollListener;
		this.myView = myView;
	}

	public interface OnScrollListener {
		void onScroll(float percent);
	}

}
